package com.hp.attendance.dao;

import com.hp.attendance.entity.Attendance;
import com.hp.attendance.entity.Menu;
import com.hp.attendance.util.BaseDAO;

import javax.xml.crypto.Data;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;


public class HomepageClockInDao extends BaseDAO {
    /**
     * 上班签到
     * @param attendance
     */
    public void addClockIn(Attendance attendance) throws SQLException, IOException, ClassNotFoundException {
       String sql = "insert into attendance values(null,?,?,?,?,?,null,null,null,null)";
       Object[] obj = {attendance.getEmployee_number(),attendance.getDay(),attendance.getTime_type(),attendance.getStart_time(),attendance.getStart_type()};
       addOrUpdOrDel(sql,obj);
    }

    /**
     * 下班签到
     * @param attendance
     */
    public void updateClockIn(Attendance attendance) throws SQLException, IOException, ClassNotFoundException {
        String sql = "update attendance set time_type=?,end_time=?,end_type=? where day=? and employee_number=?";
        Object[] obj = {attendance.getTime_type(),attendance.getEnd_time(),attendance.getEnd_type(),attendance.getDay(),attendance.getEmployee_number()};
        addOrUpdOrDel(sql,obj);
    }

    /**
     * 根据日期查询考勤信息
     * @param day
     * @return
     */
    public Attendance getAttendance(Date day, int employee_number) throws SQLException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        String sql ="select * from attendance where day=? and employee_number=?;";
        Object[] obj = {day,employee_number};
        Attendance attendance = queryOne(sql, obj, new Attendance());
        return attendance;
    }

}
